import 'package:word_range_client/pojo/vo/ConditionVo.dart';
import 'package:word_range_client/pojo/vo/EventVo.dart';

import '../repositories/EventRepository.dart';

class EventViewModel {

  static Future<List<EventVo>> getAllEvent() async{
    return await EventRepository.getAllEvent().then((value) {
      if(value.total! > 0){
        List<EventVo> eventList = [];
        for(var event in value.list!){
          eventList.add(EventVo.fromJson(event));
        }
        return eventList;
      }else{
        throw Exception("获取活动列表失败");
      }
    });
  }

  static Future<List<ConditionVo>> getConditionListByEvent(String eventId) async{
    return await EventRepository.getConditionListByEvent(eventId).then((value) {
      if(value.code == 1){
        List<ConditionVo> conditionList = [];
        for(var condition in value.data){
          conditionList.add(ConditionVo.fromJson(condition));
        }
        return conditionList;
      }else{
        throw Exception("获取活动列表失败");
      }
    });
  }
}